package org.repo.ant.tasks;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Jar;
import org.repo.ant.registry.RepoRegistry;
import org.repo.ant.util.Util;
import org.repo.ant.util.ValidationUtil;

public class RepoJar extends Jar{
	
	protected String repo;
	protected String repoBase;
	protected String repoDirectory;
	
	@Override
	public void execute() throws BuildException {
		try{
			super.execute();
			
			ValidationUtil.RepoJar.validateParams(repo, repoBase, repoDirectory);
			RepoRegistry.get().setRepo(repo, repoBase);
			Util.copy(zipFile, RepoRegistry.get().getRepoPath(repo, repoDirectory));
		}
		catch(BuildException bE){
			throw bE;
		}
		catch(Throwable t){
			t.printStackTrace();
			throw new BuildException(t);
		}		
	}	

	public String getRepo() {
		return repo;
	}

	public void setRepo(String repo) {
		this.repo = repo;
	}

	public String getRepoBase() {
		return repoBase;
	}

	public void setRepoBase(String repoBase) {
		this.repoBase = repoBase;
	}

	public String getRepoDirectory() {
		return repoDirectory;
	}

	public void setRepoDirectory(String repoDirectory) {
		this.repoDirectory = repoDirectory;
	}

	
}
